package com.cxxx.guns.modular.portal.controller;
//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='
//
//
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//               佛祖保佑         永无BUG
//

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.cxxx.guns.modular.backend.model.News;
import com.cxxx.guns.modular.backend.pojo.NewsPojo;
import com.cxxx.guns.modular.backend.pojo.Pages;
import com.cxxx.guns.modular.backend.service.INewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.List;

/**
 * @author: yyi
 * @date: 2018/9/16 12:24
 * @parameters:
 * @desc:
 **/
@Controller
@RequestMapping(value = "/portal")
public class ListController {
    private static String PREFIX="/portal/";
    @Autowired
    private INewsService newsService;
    @RequestMapping(value = "/newslist/{model}")
    public String ListNews(@PathVariable("model") String mod, Model model){
        Wrapper<News> wrapper = new EntityWrapper<News>();
        //拼接查询条件
        wrapper.eq("model",mod).orderBy("create_time",false);
        List<News> list = newsService.selectList(wrapper);
        model.addAttribute("list",list);
        return PREFIX +"childhtml/student/in/in/starlist.html";

    }
    @RequestMapping(value = "/newslistPages/{model}/{currentPage}")
    public String ListNewsPages(@PathVariable("model") int mod,@PathVariable("currentPage") int currentPage,Model model){
        //分页的页数写死就是每页有十条
        Page<News> page1 = new Page<News>(currentPage,3);
        Wrapper<News> wrapper = new EntityWrapper<>();
        /*进行设置不同的model进行不同的查询*/
        wrapper.eq("model",mod).orderBy("create_time",false);
        Page<News> pages = newsService.selectPage(page1,wrapper);
        Pages pg = new Pages();
        if (mod==1){
            pg.setModel("校园动态");
        }else if(mod==2){
            pg.setModel("通知公告");
        }else if(mod==3){
            pg.setModel("家校互动");
        }else if(mod==4){
            pg.setModel("政务公开");
        }else if(mod==5){
            pg.setModel("校务公开");
        }else if(mod==6){
            pg.setModel("德育园地");
        }else if(mod==7){
            pg.setModel("国旗下讲话");
        }else if(mod==8){
            pg.setModel("制度文件");
        }else if(mod==9){
            pg.setModel("党工团园地");
        }else if(mod==10){
            pg.setModel("健康之友");
        }else if(mod==11){
            pg.setModel("书香校园");
        }else if(mod==12){
            pg.setModel("团队在线");
        }else if(mod==13){
            pg.setModel("主题活动");
        }else if(mod==14){
            pg.setModel("卫生角");
        }else if(mod==15){
            pg.setModel("教学动态");
        }else if(mod==16){
            pg.setModel("教育科研");
        }else if(mod==17){
            pg.setModel("校本培训");
        }else if(mod==18){
            pg.setModel("教学反思");
        }else if(mod==19){
            pg.setModel("读书工程");
        }else if(mod==20){
            pg.setModel("党建在线");
        }else if(mod==21){
            pg.setModel("招生政策");
        }else if(mod==22){
            pg.setModel("评估督导");
        }
        pg.setRecords(pages.getRecords());
        pg.setCurrentPage(pages.getCurrent());
        pg.setPageSize(pages.getSize());
        pg.setTotal(pages.getPages());
        pg.setCurrentPagePrevious(pages.getCurrent()+1);
        pg.setCurrentPageNext(pages.getCurrent()+2);
        model.addAttribute("pg",pg);
        return PREFIX +"childhtml/student/in/in/starlistPages.html";
    }
    //上一页
    @RequestMapping(value = "/newslistprevious/{model}/{currentPage}")
    public String TurnPagesPrevious(@PathVariable("model") int mod,@PathVariable("currentPage") int currentPage,Model model){
        int currentPage1 = currentPage-1;
        if (currentPage1!=0){
            Page<News> page = new Page<News>(currentPage1,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            if (mod==1){
                pg.setModel("校园动态");
            }else if(mod==2){
                pg.setModel("通知公告");
            }else if(mod==3){
                pg.setModel("家校互动");
            }else if(mod==4){
                pg.setModel("政务公开");
            }else if(mod==5){
                pg.setModel("校务公开");
            }else if(mod==6){
                pg.setModel("德育园地");
            }else if(mod==7){
                pg.setModel("国旗下讲话");
            }else if(mod==8){
                pg.setModel("制度文件");
            }else if(mod==9){
                pg.setModel("党工团园地");
            }else if(mod==10){
                pg.setModel("健康之友");
            }else if(mod==11){
                pg.setModel("书香校园");
            }else if(mod==12){
                pg.setModel("团队在线");
            }else if(mod==13){
                pg.setModel("主题活动");
            }else if(mod==14){
                pg.setModel("卫生角");
            }else if(mod==15){
                pg.setModel("教学动态");
            }else if(mod==16){
                pg.setModel("教育科研");
            }else if(mod==17){
                pg.setModel("校本培训");
            }else if(mod==18){
                pg.setModel("教学反思");
            }else if(mod==19){
                pg.setModel("读书工程");
            }else if(mod==20){
                pg.setModel("党建在线");
            }else if(mod==21){
                pg.setModel("招生政策");
            }else if(mod==22){
                pg.setModel("评估督导");
            }
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/student/in/in/starlistPages.html";

        }else{
            //分页的页数写死就是每页有十条
            Page<News> page = new Page<News>(currentPage,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            if (mod==1){
                pg.setModel("校园动态");
            }else if(mod==2){
                pg.setModel("通知公告");
            }else if(mod==3){
                pg.setModel("家校互动");
            }else if(mod==4){
                pg.setModel("政务公开");
            }else if(mod==5){
                pg.setModel("校务公开");
            }else if(mod==6){
                pg.setModel("德育园地");
            }else if(mod==7){
                pg.setModel("国旗下讲话");
            }else if(mod==8){
                pg.setModel("制度文件");
            }else if(mod==9){
                pg.setModel("党工团园地");
            }else if(mod==10){
                pg.setModel("健康之友");
            }else if(mod==11){
                pg.setModel("书香校园");
            }else if(mod==12){
                pg.setModel("团队在线");
            }else if(mod==13){
                pg.setModel("主题活动");
            }else if(mod==14){
                pg.setModel("卫生角");
            }else if(mod==15){
                pg.setModel("教学动态");
            }else if(mod==16){
                pg.setModel("教育科研");
            }else if(mod==17){
                pg.setModel("校本培训");
            }else if(mod==18){
                pg.setModel("教学反思");
            }else if(mod==19){
                pg.setModel("读书工程");
            }else if(mod==20){
                pg.setModel("党建在线");
            }else if(mod==21){
                pg.setModel("招生政策");
            }else if(mod==22){
                pg.setModel("评估督导");
            }
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/student/in/in/starlistPages.html";
        }


    }
    //下一页
    @RequestMapping(value = "/newslistnext/{model}/{total}/{currentPage}")
    public String TurnPagesNext(@PathVariable("model") int mod,@PathVariable("total") int total,@PathVariable("currentPage") int currentPage,Model model){
        int currentPage1 = currentPage+1;
        if (currentPage1<=total){
            Page<News> page = new Page<>(currentPage1,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            if (mod==1){
                pg.setModel("校园动态");
            }else if(mod==2){
                pg.setModel("通知公告");
            }else if(mod==3){
                pg.setModel("家校互动");
            }else if(mod==4){
                pg.setModel("政务公开");
            }else if(mod==5){
                pg.setModel("校务公开");
            }else if(mod==6){
                pg.setModel("德育园地");
            }else if(mod==7){
                pg.setModel("国旗下讲话");
            }else if(mod==8){
                pg.setModel("制度文件");
            }else if(mod==9){
                pg.setModel("党工团园地");
            }else if(mod==10){
                pg.setModel("健康之友");
            }else if(mod==11){
                pg.setModel("书香校园");
            }else if(mod==12){
                pg.setModel("团队在线");
            }else if(mod==13){
                pg.setModel("主题活动");
            }else if(mod==14){
                pg.setModel("卫生角");
            }else if(mod==15){
                pg.setModel("教学动态");
            }else if(mod==16){
                pg.setModel("教育科研");
            }else if(mod==17){
                pg.setModel("校本培训");
            }else if(mod==18){
                pg.setModel("教学反思");
            }else if(mod==19){
                pg.setModel("读书工程");
            }else if(mod==18){
                pg.setModel("党建在线");
            }else if(mod==19){
                pg.setModel("招生政策");
            }else if(mod==22){
                pg.setModel("评估督导");
            }
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/student/in/in/starlistPages.html";

        }else{
            //分页的页数写死就是每页有十条
            Page<News> page = new Page<>(currentPage,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            if (mod==1){
                pg.setModel("校园动态");
            }else if(mod==2){
                pg.setModel("通知公告");
            }else if(mod==3){
                pg.setModel("家校互动");
            }else if(mod==4){
                pg.setModel("政务公开");
            }else if(mod==5){
                pg.setModel("校务公开");
            }else if(mod==6){
                pg.setModel("德育园地");
            }else if(mod==7){
                pg.setModel("国旗下讲话");
            }else if(mod==8){
                pg.setModel("制度文件");
            }else if(mod==9){
                pg.setModel("党工团园地");
            }else if(mod==10){
                pg.setModel("健康之友");
            }else if(mod==11){
                pg.setModel("书香校园");
            }else if(mod==12){
                pg.setModel("团队在线");
            }else if(mod==13){
                pg.setModel("主题活动");
            }else if(mod==14){
                pg.setModel("卫生角");
            }else if(mod==15){
                pg.setModel("教学动态");
            }else if(mod==16){
                pg.setModel("教育科研");
            }else if(mod==17){
                pg.setModel("校本培训");
            }else if(mod==18){
                pg.setModel("教学反思");
            }else if(mod==19){
                pg.setModel("读书工程");
            }else if(mod==20){
                pg.setModel("党建在线");
            }else if(mod==21){
                pg.setModel("招生政策");
            }else if(mod==22){
                pg.setModel("评估督导");
            }
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/student/in/in/starlistPages.html";
        }


    }
    //制度文件
    @RequestMapping(value = "/newslistPagesFile/{model}/{currentPage}")
    public String ListNewsPagesFile(@PathVariable("model") int mod,@PathVariable("currentPage") int currentPage,Model model){
        //分页的页数写死就是每页有十条
        Page<News> page1 = new Page<News>(currentPage,3);
        Wrapper<News> wrapper = new EntityWrapper<>();
        /*进行设置不同的model进行不同的查询*/
        wrapper.eq("model",mod).orderBy("create_time",false);
        Page<News> pages = newsService.selectPage(page1,wrapper);
        Pages pg = new Pages();
        pg.setRecords(pages.getRecords());
        pg.setCurrentPage(pages.getCurrent());
        pg.setPageSize(pages.getSize());
        pg.setTotal(pages.getPages());
        pg.setCurrentPagePrevious(pages.getCurrent()+1);
        pg.setCurrentPageNext(pages.getCurrent()+2);
        model.addAttribute("pg",pg);
        return PREFIX +"childhtml/teacher/teachtv/law/starlist.html";
    }
    //上一页（制度文件）
    @RequestMapping(value = "/newslistpreviousFile/{model}/{currentPage}")
    public String TurnPagesPreviousFile(@PathVariable("model") int mod,@PathVariable("currentPage") int currentPage,Model model){
        int currentPage1 = currentPage-1;
        if (currentPage1!=0){
            Page<News> page = new Page<News>(currentPage1,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/teacher/teachtv/law/starlist.html";

        }else{
            //分页的页数写死就是每页有十条
            Page<News> page = new Page<News>(currentPage,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/teacher/teachtv/law/starlist.html";
        }


    }
    //下一页（制度文件）
    @RequestMapping(value = "/newslistnextFile/{model}/{total}/{currentPage}")
    public String TurnPagesNextFile(@PathVariable("model") int mod,@PathVariable("total") int total,@PathVariable("currentPage") int currentPage,Model model){
        int currentPage1 = currentPage+1;
        if (currentPage1<=total){
            Page<News> page = new Page<>(currentPage1,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/teacher/teachtv/law/starlist.html";

        }else{
            //分页的页数写死就是每页有十条
            Page<News> page = new Page<>(currentPage,3);
            Wrapper<News> wrapper = new EntityWrapper<>();
            /*进行设置不同的model进行不同的查询*/
            wrapper.eq("model",mod).orderBy("create_time",false);
            Page<News> pages = newsService.selectPage(page,wrapper);
            Pages pg = new Pages();
            pg.setRecords(pages.getRecords());
            pg.setCurrentPage(pages.getCurrent());
            pg.setPageSize(pages.getSize());
            pg.setTotal(pages.getPages());
            pg.setCurrentPagePrevious(pages.getCurrent()+1);
            pg.setCurrentPageNext(pages.getCurrent()+2);
            model.addAttribute("pg",pg);
            return PREFIX +"childhtml/teacher/teachtv/law/starlist.html";
        }


    }
    /*制度文件查看详情*/
    @RequestMapping(value = "/FileDetail/{id}")
    public String FileDetail(@PathVariable("id") int id,Model model){
        News news = newsService.selectById(id);
        Date date = news.getCreateTime();
        /*制度文件的id分类为8，直接穿进去8就可以*/
        News next = newsService.selectNewsNext(8,date);
        News previous = newsService.selectNewsPrevious(8,date);
        NewsPojo newsPojo = new NewsPojo();
        newsPojo.setNews(news);
        if (next!=null){
            newsPojo.setNextItemHead(next.getNewsTitle());
            newsPojo.setNextItemId(next.getId());
        }else{
            newsPojo.setNextItemHead("无");
            newsPojo.setNextItemId(news.getId());
        }
        if (previous!=null){
            newsPojo.setPreviousHead(previous.getNewsTitle());
            newsPojo.setPreviousId(previous.getId());
        }else {
            newsPojo.setPreviousHead("无");
            newsPojo.setPreviousId(news.getId());
        }
        List<News> list = newsService.getListIndex(news.getModel());
        model.addAttribute("news",newsPojo);
        model.addAttribute("list",list);
        return PREFIX +"childhtml/teacher/teachtv/law/starmsg.html";

    }


}
